package com.itheima.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.pojo.SmsFlashPromotionSession;
import com.itheima.pojo.UmsResourceCategory;
import com.itheima.service.SmsFlashPromotionSessionService;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("flashSession")
public class SmsFlashPromotionSessionController {

    @Autowired
    private SmsFlashPromotionSessionService smsFlashPromotionSessionService;

    /**
     * 添加场次
     * @param smsFlashPromotionSession
     * @return
     */
    @PostMapping("create")
    public Result create(@RequestBody SmsFlashPromotionSession smsFlashPromotionSession){

        smsFlashPromotionSessionService.save(smsFlashPromotionSession);
        return Result.success(null);
    }

    /**
     * 删除场次
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        smsFlashPromotionSessionService.deleteByIds(id);
        return Result.success(null);
    }

    /**
     * 获取全部场次
     * @return
     */
    @GetMapping("list")
    public Result listAll(){
        List<SmsFlashPromotionSession> list = smsFlashPromotionSessionService.listAll();
        return Result.success(list);
    }

    /**
     * 修改启用的状态
     * @param status
     * @param id
     * @return
     */
    @PostMapping("update/status/{id}")
    public Result updateStatus(Integer status,@PathVariable("id") Integer id){
        smsFlashPromotionSessionService.updateStatus(status,id);
        return Result.success("修改状态成功");
    }

    /**
     * 获取全部可选场次及其数量
     * @param flashPromotionId
     * @return
     */
    @GetMapping("selectList")
    public Result selectList(Integer flashPromotionId){
        Result result=smsFlashPromotionSessionService.selectList(flashPromotionId);
        return Result.success(null);
    }

    /**
     * 修改场次
     * @param id
     * @param smsFlashPromotionSession
     * @return
     */
    @PostMapping("update/{id}")
    public Result updateSession(@PathVariable("id")Integer id,@RequestBody SmsFlashPromotionSession smsFlashPromotionSession){
        smsFlashPromotionSessionService.updateSession(id,smsFlashPromotionSession);
        return Result.success(null);
    }

    /**
     *
     获取场次详情
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result findById(@PathVariable("id") Integer id){
        SmsFlashPromotionSession smsFlashPromotionSession = smsFlashPromotionSessionService.findById(id);
        return Result.success(smsFlashPromotionSession);
    }
}
